home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
RTF
/
search_path.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
121 lines
// search_path.h -
// Copyright (c) 1990, 1991, 1992 Convex Computer Corporation
// All rights reserved.
/**********************************************************************
** File: search_path.h
** Ident: $CHeader: search_path.h 1.1 92/06/11 18:44:51 $
** Language: C++
** Purpose:
** Types
None
** Constants:
** Global Data:
** Static Data:
** Global Functions:
** Public methods:
** Private methods:
** Static Public methods:
** Static Private methods:
** Notes:
** Revision History:
** Who Date Description
--- -------- ----------------------------------------------------
DWC 1-31-92 initial implementation
**********************************************************************/
/* for F_OK, etc. */
#include <unistd.h>
/* for FILE */
#include <stdio.h>
class SearchPath{
public:
typedef const char* Filename;
typedef const char* Path;
/* are these in an include file somewhere? */
enum{max_name_len = 255, max_path_len = 1023};
SearchPath(Path p = 0);
~SearchPath();
char* lookup(Filename, int mode, const char* extensions=0);
/* USE : real_path = sp.lookup("filename", R_OK, ":.Z");
* delete real_path
* ERRS: return 0
*/
FILE* open(Filename, const char* extensions=0);
/* USE : fp = sp.open("filename", ":.Z")
* to read from filename
*/
int add_directories(Path);
/* USE : total = sp.add_directories("/here:/there:other/place");
*/
Filename first_dir();
Filename next_dir();
/* USE : for(d = sp.first_dir(); d; d = sp.next_dir())
* do stuff with d
*/
private:
static char buffer[max_path_len+1];
static int len;
Filename* dirs;
int dir_qty;
Filename* current;
int allocated;
void grow(int);
/* USE: grow(to_new_size);
*/
Filename find(Filename, int mode, const char* extensions=0);
};
inline SearchPath::SearchPath(Path path){
dirs = 0;
allocated = -1;
dir_qty = 0;
current = 0;
add_directories(path);
}
inline SearchPath::~SearchPath()
{
delete [] dirs;
}
inline SearchPath::Filename
SearchPath::first_dir()
{
current = dirs;
return current ? *current : 0;
}
inline SearchPath::Filename
SearchPath::next_dir()
{
if(!current)
return first_dir();
else
return (++current - dirs <dir_qty) ? *current : 0;
}